package com.hsd.znsh.converter;

import com.hsd.znsh.entity.Batch;
import com.hsd.znsh.entity.Opinion;
import com.hsd.znsh.enums.BatchStatusEnum;
import com.hsd.znsh.pojo.output.BatchVO;
import com.hsd.znsh.pojo.output.OpinionVO;
import com.hsd.znsh.repository.HostRepository;
import com.hsd.znsh.repository.UserRepository;
import com.hsd.znsh.utils.BeanUtil;
import com.hsd.znsh.utils.EnumUtil;

import java.util.ArrayList;
import java.util.List;

/*
 * @auther: wangjiacai
 *
 * @create: 2018-04-26 14:48:19
 */
public class OpinionConverter {

    public static OpinionVO converterToOpinionVO(Opinion opinion, UserRepository userRepository){
        OpinionVO opinionVO=new OpinionVO();
        BeanUtil.copyProperties(opinion,opinionVO);
        if(opinion.getUserId()!=null){
            opinionVO.setCreateUsername(userRepository.findOne(opinion.getUserId()).getUsername());
        }
        return  opinionVO;
    }



    public static List<OpinionVO> converterToOpinionVOList(List<Opinion> opinions, UserRepository userRepository){
        List<OpinionVO> list=new ArrayList<>();
        for(Opinion opinion:opinions){
            list.add(converterToOpinionVO(opinion,userRepository));
        }
        return  list;
    }


}
